package org.example.struct.array;

import com.alibaba.fastjson.JSON;

/**
 * @author liyishan
 * @date 2023/8/10 10:22
 * @apiNote
 */

public class Test00941ValidMountainArray {
    public static void main(String[] args) {
        int[] aliceSizes = new int[]{1,7,9,5,4,1,2};
        boolean result = test(aliceSizes);
        System.out.println(JSON.toJSON(result));
    }

    public static boolean test(int[] arr){
        int n = arr.length;
        if(n <3){
            return false;
        }
        int max = Integer.MIN_VALUE,right = -1;
        int min = Integer.MIN_VALUE, left = -1;
        for(int i = 0;i<n;i++){
            if(arr[i] <= max){
                right = i-1;
                break;
            }else{
                max = arr[i];
            }

        }
        for(int i = 0 ;i<n;i++){
            if(arr[n-i-1] <= min){
                left = n-i;
                break;
            }else{
                min = arr[n-i-1];
            }
        }
        if(left == right){
            return true;
        }
        return false;
    }
    public static boolean test1(int[] arr){
        int N = arr.length;
        int i = 0;
        // 递增扫描
        while (i + 1 < N && arr[i] < arr[i + 1]) {
            i++;
        }
        // 最高点不能是数组的第一个位置或最后一个位置
        if (i == 0 || i == N - 1) {
            return false;
        }
        // 递减扫描
        while (i + 1 < N && arr[i] > arr[i + 1]) {
            i++;
        }
        return i == N - 1;
    }
}
